package DataAccess;

import java.util.*;

//C# TO JAVA CONVERTER TODO TASK: The interface type was changed to the closest equivalent Java type, but the methods implemented will need adjustment:
public abstract class DataAccessCollectionBase implements Collection
{
	public DataAccessCollectionBase()
	{
		SQL = new SqlAccess();
		_DataTable = BuildTable();
	}
	protected SqlAccess SQL;
	protected DataTable _DataTable;
	protected abstract DataTable BuildTable();
	public String Sort = "";
 public BillySir.Web.UI.WebControls.ChangePage ChangePage;

	public String Fields = "";
	public String TableName = "";

	protected final boolean ListBySql(String sql)
	{
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if(DEBUG)
		sql = Helper.BeautifulSql(sql);
		if (Sort.length() > 0)
		{
			sql += " Order By " + Sort;
		}
		if (ChangePage != null)
		{
			tangible.RefObject<String> tempRef_sql = new tangible.RefObject<String>(sql);
			ChangePage.PageSql(tempRef_sql);
			sql = tempRef_sql.argValue;
			if (ChangePage.CountReload)
			{
				ChangePage.Count = SQL.GetIntValue(ChangePage.CountSql);
			}
		}
		_DataTable = GetDataTable(sql);
//#else
		if (Sort.length() > 0)
		{
			sql += " Order By " + Sort;
		}
		if (ChangePage != null)
		{
			tangible.RefObject<String> tempRef_sql2 = new tangible.RefObject<String>(sql);
			ChangePage.PageSql(tempRef_sql2);
			sql = tempRef_sql2.argValue;
			if (ChangePage.CountReload)
			{
				ChangePage.Count = sql.GetIntValue(ChangePage.CountSql);
			}
		}
		try
		{
			_DataTable = GetDataTable(sql);
		}
		catch (java.lang.Exception e)
		{
			return false;
		}
//#endif
		return true;
	}

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region Foreach
	public final void CopyTo(Array myArr, int index)
	{
		for (DataRow dr : _DataTable.Rows)
		{
			myArr.SetValue(dr,index);
			index++;
		}
	}
	public final int size()
	{
		return (_DataTable == null ? 0 : _DataTable.Rows.size());
	}
	public final boolean getIsSynchronized()
	{
		return false;
	}
	public final Object getSyncRoot()
	{
		return this;
	}

	protected DataAccessBase GetItemByIndex(int index)
	{
		throw new RuntimeException("ʵ����û��override�˷���");
	}

	public final Iterator GetEnumerator()
	{
		return new Enumerator(_DataTable.Rows, this);
	}

//C# TO JAVA CONVERTER TODO TASK: The interface type was changed to the closest equivalent Java type, but the methods implemented will need adjustment:
	public static class Enumerator implements Iterator
	{
		private DataRowCollection DataRows;
		private int Cursor;
		private DataAccessCollectionBase DACB;
		public Enumerator(DataRowCollection dataRows, DataAccessCollectionBase DACB)
		{
			this.DataRows = dataRows;
			this.DACB = DACB;
			Cursor = -1;
		}
		public final void Reset()
		{
			Cursor = -1;
		}
		public final boolean MoveNext()
		{
			if (Cursor < DataRows.size())
			{
				Cursor++;
			}

			return Cursor != DataRows.size();
		}
		private Object getCurrent()
		{
			if ((Cursor < 0) || (Cursor == DataRows.size()))
			{
				throw new IllegalStateException();
			}

			return DACB.GetItemByIndex(Cursor);
		}
	}
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion Foreach

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region Collection Operation
	public final void Add(DataAccessBase daObj)
	{
		_DataTable.Rows.Add(daObj._DataRow);
	}
	public final void Clear()
	{
		_DataTable.Rows.Clear();
	}
	public final void InsertAt(DataAccessBase dataAccess, int pos)
	{
		_DataTable.Rows.InsertAt(dataAccess._DataRow,pos);
	}
	public final void Remove(DataAccessBase dataAccess)
	{
		_DataTable.Rows.Remove(dataAccess._DataRow);
	}
	public final void RemoveAt(int index)
	{
		_DataTable.Rows.RemoveAt(index);
	}
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion Collection Operation

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region Prepare for transaction
	protected final int ExecuteSQL(String sql)
	{
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if(DEBUG)
		sql = Helper.BeautifulSql(sql);
//#endif
		return SQL.ExecuteSQL(sql);
	}
	protected final DataTable GetDataTable(String sql)
	{
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if(DEBUG)
		sql = Helper.BeautifulSql(sql);
//#endif
		return SQL.GetDataTable(sql);
	}
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion Prepare for transaction

	protected final String ToSQLParamStr(String str)
	{
		return Helper.ToSQLParamStr(str);
	}

}